<template>
    <div class="about">
		<!-- <banner isHome="true"></banner> -->
        <div class="site-content">
            <div class="content-warp">
                <div class="about-me about-info">
                    <section-title id="Guestbook"><span>❤</span>添加文章</section-title>
                    <div class="info-card">
						
						文章图片：
						<el-image
						    style="width: 100px; height: 100px"
						    :src="photo"
						    :zoom-rate="1.2"
								 fit="cover"
						/>
						<el-upload
							drag
							action="http://localhost:8090/upload/image"
							name="multipartFile"
							:on-success="uploadImageSuccess"
						></el-upload>
						
						<el-select v-model="type" clearable placeholder="请选择文章分类">
						  <el-option
							v-for="item in articleType"
							:key="item.id"
							:label="item.name"
							:value="item.id">
						  </el-option>
						</el-select>
						文章标题：<el-input v-model="title"></el-input>
						<vue-editor v-model="content"></vue-editor>
						<el-button @click="PreviewDialogVisible=true">预览</el-button>
						<el-button @click="submit()">提交</el-button>
					</div>
					<el-dialog draggable :visible.sync="PreviewDialogVisible" >
						<div style="font-size: 30px; font-weight: 700;text-align: center;line-height: 80px;margin-top: -40px;">预览正文</div>
						<div class="dialogDiv"><p v-html="content"></p></div>
					</el-dialog>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
	import sectionTitle from '@/components/section-title'
	import { VueEditor } from "vue2-editor";
	import { getTypeList, insertArticle } from '@/api/article'
	export default {
	    name: "myArticle",
	    data() {
	        return {
				content:'',
				type: '',
				articleType: [],
				title: '',
				PreviewDialogVisible: false,
				photo: ''
	        }
	    },
	    components: {
			sectionTitle,
			VueEditor
	    },
	    methods: {
			uploadImageSuccess(response, uploadFile, uploadFiles){
				this.photo = response.photo
			},
			async getData() {
				let data = await getTypeList()
				this.articleType = data.getArticleTypeList
			},
			async submit() {
				if (this.photo == '') {
					alert("图片不能为空")
					return
				}
				if (this.title == '') {
					alert("标题不能为空")
					return
				}
				if (this.content == '') {
					alert("内容不能为空")
					return
				}
				if (this.type == '') {
					alert("文章分类未选择")
					return
				}
				let data = await insertArticle({
					title: this.title,
					context: this.content,
					articleTypeId: this.type,
					imageUrl: this.photo
				})
				if (data.code == 200) {
					alert("添加成功")
				}
				this.content = ''
				this.title = ''
				this.photo = ''
			}
		},
	    mounted() {
			this.getData()
	    }
	}
</script>

<style scoped lang="less">
    .about {
        padding-top: 40px;
    }
	
	.list-group-striped > .list-group-item {
		border-left: 0;
		border-right: 0;
		border-radius: 0;
		padding-left: 0;
		padding-right: 0;
	}
	.list-group-item {
		border-bottom: 1px solid #e7eaec;
		border-top: 1px solid #e7eaec;
		margin-bottom: -1px;
		padding: 11px 0;
		font-size: 13px;
	}
	.pull-right {
		float: right !important;
	}
	.focusinfo {
	    position: relative;
	    max-width: 800px;
	    padding: 0 10px;
	    top: 40%;
	    left: 50%;
	    transform: translate(-50%,-50%);
	    -webkit-transform: translate(-50%,-50%);
	    text-align: center;
	    img {
			margin-top: 100px;
	        width: 80px;
	        height: 80px;
	        border-radius: 50%;
	        border: 3px solid rgba(255, 255, 255, 0.3);
	    }
	}

    .content-warp {
        margin-top: 80px;

        .about-info {
            margin: 30px 0;

            span {
                color: red;
                margin-right: 10px;
            }

            .info-card {
                min-height: 100px;
                padding: 20px;
                border-radius: 3px;
                margin: 30px 0 50px 0;
                box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
                p{
                    line-height: 1.7rem;
                }
            }
        }
        .contactForm{
			text-align: center;
            width: 100%;
            padding: 20px;
            .form-item{
                align-items: center;
                display: flex;
                &:not(:last-child){
                    margin-bottom: 20px;
                }
                label{
                  width: 80px;
                }
                .v{
                    min-height: 40px;
                    line-height: 20px;
                    border-radius: 3px;
                    padding: 2px 10px;
                    outline:none;
                    border: 1px solid #8fd0cc;
                    width: 100%;
                    resize: vertical;
                }
                button{
                    width: 100px;
                    height: 40px;
                    border-radius: 3px;
                    outline:0;
                    border-style: none;
                    cursor: pointer;
                    background-color: #409eff;
                    color: white;
                    &:hover{
                        opacity: 0.8;
                    }
                }
            }
        }
    }
	
	.more{
	    margin: 50px 0;
	    .more-btn{
	        width: 100px;
	        height: 40px;
	        line-height: 40px;
	        text-align: center;
	        color: #ADADAD;
	        border: 1px solid #ADADAD;
	        border-radius: 20px;
	        margin: 0 auto;
	        cursor: pointer;
	        &:hover{
	            color: #8fd0cc;
	            border: 1px dashed #8fd0cc;
	        }
	    }
	}
	
	.dialogDiv {
	            overflow: auto;
	        }

    /*******/
    @media (max-width: 800px) {
        .content-warp {
            margin-top: 0;
        }
    }
</style>